package sjg.practice.WBtest;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class DBUtil {
	public static final String DRIVER = "com.mysql.jdbc.Driver";
	public static final String USERNAME = "root";
	public static final String PASSWORD = "123456";
	public static final String URL = "jdbc:mysql://localhost:3306/yonghumima";
	private static Connection conn = null;
	private static Statement stmt = null;
	private static ResultSet rs =null;
	
	public static int link(String demo,String demo1) {
		try{
			Class.forName(DRIVER);
			conn = DriverManager.getConnection(URL,USERNAME,PASSWORD);
			stmt = conn.createStatement();
			String sql = "SELECT * FROM sjg";
			rs = stmt.executeQuery(sql);
			while(rs.next()){
				String username = rs.getString("name");
				String password = rs.getString("password");
				if(demo.equals(username)){
					if(demo1.equals(password)){
						return 1;
					}
				}
			}
		}
		catch(Exception ex){
			ex.printStackTrace();
		}
		finally{
			try{
				if(rs!=null){
					rs.close();
				}
				if(stmt!=null){
					stmt.close();
				}
				if(conn!=null){
					conn.close();
				}
			}
			catch(SQLException ex){
				ex.printStackTrace();
			}
		}
		return -1;
	}	


}
